using System.Collections.Generic;
using Token = TBit.Compile.ASMCompile.Token;
using TBit.Compile;

namespace TBit.Instrcutions {
    public static class Ofscjmp {
        public static int Compile(List<Token> tokens,VM vm,int i) {
            return ASMCompile.StructureInstruction_OPCODE_R_R_R(Opcode.OFSCJMP,tokens,vm,i);
        }

        public static Instruction Create(RegisterIndex a,RegisterIndex b,RegisterIndex c) {
            Instruction inst = new Instruction();
            inst.opcode = Opcode.OFSCJMP;
            inst.args.Add(new InstructionArgData(a));
            inst.args.Add(new InstructionArgData(b));
            inst.args.Add(new InstructionArgData(c));
            return inst;
        }

        public static int Run(VM vm,Instruction inst){
            InstructionArgData arg1 = inst.args[0];
            InstructionArgData arg2 = inst.args[1];
            InstructionArgData arg3 = inst.args[2];
            Data reg = vm.registers[(int)arg1.register];
            Data reg2 = vm.registers[(int)arg2.register];
            Data reg3 = vm.registers[(int)arg3.register];
            if(reg.type == DataType.Boolean)
            {
                if(reg2.type == DataType.Number && reg3.type == DataType.Number)
                {
                    if(reg.boolean_data)
                    {
                        return (int)reg2.number_data;
                    }
                    else
                    {
                        return (int)reg3.number_data;
                    }
                }
            }
            return 1;
        }
    }
}